<?php
/**
 * Created by PhpStorm.
 * User: hanbin
 * Date: 17/3/30
 * Time: 下午4:51
 */

namespace App\Http\Controllers\Zhihu;


use App\Logic\MemberLogic;
use Illuminate\Http\Request;
use Validator;

/**
 * 会员
 * Class MemberController
 * @package App\Http\Controllers\Auth
 */
class MemberController extends BaseController
{
    public function __construct()
    {
        $this->setToken(true);
        parent::__construct();
    }

    /**
     * 更新数据
     *
     * @param Request $request
     * @return array
     */
    public function updateInfo(Request $request)
    {
        $rule = [
            'school' => 'required|string',
            'face' => 'required|string',
            'username' => 'required|string',
        ];
        $message = [
            'school.required' => '学校不能为空',
            'face.required' => '头像不能为空',
            'username.required' => '用户名不能为空',
        ];
        $validator = Validator::make($request->all(), $rule, $message);
        $errors = $validator->errors()->all();
        if ($errors && !$validator->passes()) {
            return $this->error($errors[0], 206);
        }
        return MemberLogic::updateInfo($this->userId, $request->all());
    }


}